<?php
/**
 * @version		$Id: helper.php 10381 2008-06-01 03:35:53Z pasamio $
 * @package		Joomla
 * @subpackage	Menus
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

/**
 * @package		Joomla
 * @subpackage	Menus
 */
class SelectHelper
{
	
	function Select( &$row,$TableName )
	{
		$db =& JFactory::getDBO();
		//$row->id = 3;
		// If a not a new item, lets set the menu item id
		if ( $row->id ) {
			//$id = ' AND id != '.(int) $row->id;
		} else {
			$id = null;
		}

		// In case the parent was null
		if (!$row->parent) {
			$row->parent = 0;
		}

		// get a list of the menu items
		// excluding the current menu item and its child elements
		$query = 'SELECT * ' .
				' FROM #__properties_'.$TableName.' ' .
				//' WHERE menutype = '.$db->Quote($row->menutype) .
				' WHERE published != -2' .
				$id .
				' ORDER BY name';
		$db->setQuery( $query );
		$items = $db->loadObjectList();

		// establish the hierarchy of the menu
		$children = array();


		$mitems 	= array();
		

		foreach ( $items as $item ) {
			$mitems[] = JHTML::_('select.option',  $item->id, '&nbsp;&nbsp;&nbsp;'. $item->name );
		}

		$output = JHTML::_('select.genericlist',   $mitems, 'parent', 'class="inputbox" size="1"', 'value', 'text', $row->parent );
		
		//print_r($mitems);
		return $output;
	}



	function SelectAjaxPaises( &$row,$TableName,$soy_id )
	{
		$db =& JFactory::getDBO();		
		if ( $row->id ) {
			//$id = ' AND id != '.(int) $row->id;
		} else {
			$id = null;
		}
		// In case the parent was null
		
		$query = 'SELECT * ' .
				' FROM #__properties_'.$TableName.' ' .
				//' WHERE menutype = '.$db->Quote($row->menutype) .
				' WHERE published != -2' .
				//$id .
				' ORDER BY name';
				
		$db->setQuery( $query );
		$items = $db->loadObjectList();
		
		$mitems 	= array();
		

$mitems[0]->id=0;
$mitems[0]->name=JText::_( 'Country' );
		foreach ( $items as $item ) {
			$mitems[] = $item;
		}
$javascript = 'onChange="ChangeState(this.value)"';
		$output = JHTML::_('select.genericlist',   $mitems, 'cyid', 'class="inputbox" size="1"'.$javascript, 'id', 'name', $row->cyid);

		//print_r($mitems);
		
		return $output;
	}


	function SelectType( &$row,$TableName,$soy_id )
	{
		$db =& JFactory::getDBO();			
		$query = 'SELECT * ' .
				' FROM #__properties_'.$TableName.' ' .
				//' WHERE menutype = '.$db->Quote($row->menutype) .
				' WHERE published != -2' .				
				' ORDER BY name';				
		$db->setQuery( $query );
		$items = $db->loadObjectList();		
		$mitems 	= array();
$mitems[0]->id=0;
$mitems[0]->name=JText::_( 'Type' );
		foreach ( $items as $item ) {
			$mitems[] = $item;
		}
$javascript = 'onChange="ChangeState(this.value)"';
		$output = JHTML::_('select.genericlist',   $mitems, 'type', 'class="inputbox" size="1"', 'id', 'name', $row->type);
		
		return $output;
	}	
	
	
function SelectCliente( &$row,$TableName )
	{
		$db =& JFactory::getDBO();
		$query = 'SELECT * ' .
				' FROM #__users' .				
				//' WHERE gid = 100' .						
				' ORDER BY name';				
		$db->setQuery( $query );
		$items = $db->loadObjectList();
		$javascript = 'onChange="CambiarCliente(this.value)"';
		$output = JHTML::_('select.genericlist',   $items, 'mid', 'class="inputbox" size="1" '.$javascript, 'id', 'username', $row->mid );
		//print_r($mitems);
		return $output;
	}


function SelectAgent( &$row,$TableName )
	{
		$db =& JFactory::getDBO();
		$query = 'SELECT * ' .
				' FROM #__properties_profiles' .				
				//' WHERE gid = 100' .						
				' ORDER BY name';				
		$db->setQuery( $query );
		$items = $db->loadObjectList();
		$javascript = 'onChange="ChangeAgent(this.value)"';
		$output = JHTML::_('select.genericlist',   $items, 'agent_id', 'class="inputbox" size="1" '.$javascript, 'mid', 'name', $row->agent_id );
		//print_r($mitems);
		return $output;
	}







	
	
	
	
	function ParentAc( &$row )
	{
		$db =& JFactory::getDBO();
		//$row->id = 3;
		// If a not a new item, lets set the menu item id
		if ( $row->id ) {
			//$id = ' AND id != '.(int) $row->id;
		} else {
			$id = null;
		}

		// In case the parent was null
		if (!$row->parent) {
			//$row->parent = 0;
		}

		// get a list of the menu items
		// excluding the current menu item and its child elements
		$query = 'SELECT * ' .
				' FROM #__gestor_categorias_facturacion' .
				//' WHERE menutype = '.$db->Quote($row->menutype) .
				' WHERE published != -2' .
				//$id .
				' ORDER BY parent, ordering';				
		$db->setQuery( $query );
		$mitems = $db->loadObjectList();

		// establish the hierarchy of the menu
		$children = array();

		if ( $mitems )
		{
			// first pass - collect children
			foreach ( $mitems as $v )
			{
				$pt 	= $v->parent;
				$list 	= @$children[$pt] ? $children[$pt] : array();
				array_push( $list, $v );
				$children[$pt] = $list;
			}
		}

		// second pass - get an indent list of the items
		$list = JHTML::_('menu.treerecurse', 0, '', array(), $children, 9999, 0, 0 );
//print_r($list);
		// assemble menu items to the array
		$mitems 	= array();
		$mitems[] 	= JHTML::_('select.option',  '0', JText::_( 'Top' ) );

		foreach ( $list as $item ) {
			$mitems[] = JHTML::_('select.option',  $item->id, '&nbsp;&nbsp;&nbsp;'. $item->treename );
		}

		$output = JHTML::_('select.genericlist',   $mitems, 'parent', 'class="inputbox" size="10"', 'value', 'text', $row->parent );
		
		//print_r($mitems);
		//return $output;
		return $list;
	}
	
	
	
	
}


